<?php
//首页
if(!defined('IN_T')){
	die('hacking attempt');
}

$recommend = get_index_recommend();
if($recommend) {
    foreach($recommend as $key => $val) {
        $user = get_userinfo($val['pk_user_main']);
        if($user) {
            $recommend[$key] = array_merge($val, $user[0]);
        }
    }
}
$tp->assign('recommend',$recommend);

//提取首页推荐图片
function get_index_recommend(){
	$sql = "select name,thumb_path,view_uuid,profile,browsing_num,pk_user_main ".
	       "from ".$GLOBALS['Base']->table('worksmain')." where recommend=1 order by sort asc, pk_works_main desc limit 12";
	$res = $GLOBALS['Db']->query($sql);
	return $res;
}

function get_userinfo($id){
    $sql = "select nickname ".
        "from ".$GLOBALS['Base']->table('user')." where pk_user_main=".$id;
    $res = $GLOBALS['Db']->query($sql);
    return $res;
}
?>